package com.caregiver.watch.business.care.controller;

import com.caregiver.watch.business.care.model.dto.OpenHealthAlertParam;
import com.caregiver.watch.business.care.model.dto.QueryWarningHistoryParam;
import com.caregiver.watch.business.care.model.vo.AlertCountVo;
import com.caregiver.watch.business.care.model.vo.BoughtPackageInfoVo;
import com.caregiver.watch.business.care.model.vo.HealthAlertPackageInfoVo;
import com.caregiver.watch.business.care.model.vo.HealthAlertServiceInfoVo;
import com.caregiver.watch.business.care.model.vo.OpenHealthAlertVo;
import com.caregiver.watch.business.care.model.vo.WarningHistoryVo;
import com.caregiver.watch.business.care.service.HealthAlertService;
import com.caregiver.watch.common.domain.R;
import com.github.pagehelper.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: caregiver-watch
 * @author: 疆戟
 * @create: 2025-10-05 17:50
 */
@Tag(name  = "HealthAlertController", description = "健康预警")
@RestController
@RequestMapping("/health/alert")
public class HealthAlertController {

    @Autowired
    private HealthAlertService healthAlertService;

    // 查询健康预警服务信息
    @Operation(summary = "查询用户健康预警信息")
    @GetMapping("queryUserHealthAlertInfo")
    public R<HealthAlertServiceInfoVo> queryUserHealthAlertInfo() {
        return R.ok(healthAlertService.queryUserHealthAlertInfo());
    }

    // 获取已购买的套餐信息
    @Operation(summary = "获取用户已购买的套餐列表")
    @GetMapping("queryUserBoughtPackageList")
    public R<List<BoughtPackageInfoVo>> queryUserBoughtPackageList() {
        return R.ok(healthAlertService.queryUserBoughtPackageList());
    }

    // 查询健康预警套餐信息
    @Operation(summary = "查询健康预警套餐信息")
    @GetMapping("queryHealthAlertPackageInfo")
    public R<HealthAlertPackageInfoVo> queryHealthAlertPackageInfo() {
        return R.ok(healthAlertService.queryHealthAlertPackageInfo());
    }


    // 开通健康预警
    @Operation(summary = "开通健康预警")
    @PostMapping("openHealthAlert")
    public R<OpenHealthAlertVo> openHealthAlert(@RequestBody OpenHealthAlertParam param) {
        return R.ok(healthAlertService.openHealthAlert(param));
    }


    @Operation(summary = "查询预警次数统计")
    @GetMapping("queryAlertCount")
    public R<AlertCountVo> queryAlertCount(@RequestParam("startTime") @Parameter(description = "开始时间(YYYY_MM_DD)") String startTime,
                                           @RequestParam("endTime") @Parameter(description = "结束时间(YYYY_MM_DD)") String endTime) {
        return R.ok(healthAlertService.queryAlertCount(startTime, endTime));
    }

    // 查询预警历史
    @Operation(summary = "查询预警历史列表")
    @PostMapping("queryWarningHistory")
    public R<Page<WarningHistoryVo>> queryWarningHistory(@RequestBody QueryWarningHistoryParam param) {
        return R.ok(healthAlertService.queryWarningHistory(param));
    }
}
